package com.example.system.Test;

import com.example.common.core.domin.R;
import com.example.common.core.enums.ResultCode;
import com.example.common.redis.service.RedisService;
import com.example.system.Test.domain.LoginTestDTO;
import com.example.system.Test.domain.ValidationDTO;
import com.example.system.Test.service.TestService;
import com.example.system.domin.sysUser.SysUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/test")
@Slf4j
public class TestController {

    @Autowired
    private TestService testService;

    @Autowired
    private RedisService redisService;


    @GetMapping("/list")
    public List<?> list() {
        return testService.list();
    }

    @GetMapping("/add")
    public String add() {
        return testService.add();
    }

    @GetMapping("/apiFoxTest")
    public R<String> apiFoxTest(String apiId) {
        R<String> result = new R<>();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMsg(ResultCode.SUCCESS.getMsg());
        result.setData("apiFoxTest" + apiId);
        return result;
    }

    @PostMapping("/apiFoxPost")
    public R<String> apiFoxPost(@RequestBody LoginTestDTO loginTestDTO) {
        R<String> result = new R<>();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMsg(ResultCode.SUCCESS.getMsg());
        result.setData("apiFoxTest" + loginTestDTO.toString());
        return result;
    }

    @GetMapping("/log")
    public String log() {
        log.info("我是info级别的日志");
        log.error("我是error级别的日志");
        return "日志测试";
    }

    @GetMapping("/redisAndGet")
    public String redisAndGet() {
        SysUser sysUser = new SysUser();
        sysUser.setUserAccount("redisTest");
        redisService.setCacheObject("u", sysUser);
        SysUser redisUser = redisService.getCacheObject("u",SysUser.class);
        return redisUser.toString();
    }

    @GetMapping("/validation")
    public String validation(@Validated ValidationDTO validationDTO) {
        return "参数测试";
    }

}
